package com.zmn.oms.dubbo.impl.zmn.third.toutiao;

import org.apache.dubbo.config.annotation.Service;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.dubbo.dto.zmn.third.toutiao.ToutiaoCompanyAccountDIO;
import com.zmn.oms.dubbo.interfaces.zmn.third.toutiao.ToutiaoRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.third.ToutiaoCompanyAccount;
import com.zmn.oms.third.toutiao.service.HeadlinesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author xiewenbing
 *
 * @date:2020/11/30
 * description: 头条渠道H5页面接口实现
 */
@Slf4j
@Api(value = "头条渠道相关的H5接口", tags = {"头条渠道相关的H5接口"})
@Service(loadbalance = "roundrobin", timeout = 10000, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class ToutiaoRemoteServiceImpl implements ToutiaoRemoteService {

    @Autowired
    private HeadlinesService headlinesService;

    /**
     * 添加公司账号
     *
     * @param companyAccountDIOList
     * @return
     */
    @Override
    @ApiOperation(value = "添加公司账号")
    public ResponseDTO addCompanyAccount(@Valid @NotNull(message = "参数不能为空") List<ToutiaoCompanyAccountDIO> companyAccountDIOList) {

        if (CollectionUtils.isEmpty(companyAccountDIOList)) {
            return ResponseDTO.fail("参数为空");
        }

        companyAccountDIOList.forEach(companyAccountDIO -> {
            ToutiaoCompanyAccount toutiaoCompanyAccount = BeanMapper.map(companyAccountDIO,ToutiaoCompanyAccount.class);
            headlinesService.addCompanyAccount(toutiaoCompanyAccount);
        });

        return ResponseDTO.success();
    }

    /**
     * 删除公司账号
     *
     * @param secretList
     * @return
     */
    @Override
    @ApiOperation(value = "删除公司账号")
    public ResponseDTO delCompanyAccount(@Valid @NotBlank(message = "参数不能为空") List<String> secretList) {

        if (CollectionUtils.isEmpty(secretList)) {
            return ResponseDTO.fail("参数为空");
        }

        secretList.forEach(secret->{
            headlinesService.delCompanyAccount(secret);
        });

        return ResponseDTO.success();
    }
}
